const db = wx.cloud.database();
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    leixingList:['岗位类别','非文体岗位','文体岗位'],
    phone: 0,
    name:'',
    zkz:'',
    daima:'',
    theList: ''
  },
  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
    console.log(this.data.name)
  },
  zkzInput: function (e) {
    this.setData({
      zkz: e.detail.value
    })
    console.log(this.data.zkz)
  },
  
  daimaInput: function (e) {
    this.setData({
      daima: e.detail.value
    })
    console.log(this.data.daima)
  },
  bindPickerChange: function (e) {
    let num = e.detail.value;
    let that = this;
    that.setData({
      index: e.detail.value,
      leixing:that.data.leixingList[num]
    })
    console.log(that.data.leixingList[num])
  },
  close: function (e) {
    this.setData({
      fixed: !1
    })
  },
  


  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },




  getPhoneNumber(e) {
    var that = this;
    wx.cloud.callFunction({
        name: 'getMobile',
        data: {
            weRunData: wx.cloud.CloudID(e.detail.cloudID),
        }
    }).then(res => {
        that.setData({
            phone: res.result,
        })
        console.log(res.result)
        
        wx.setStorageSync('phone', res.result)
        wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/chaxun/register?actid=47412&callback=?', //接收url
            data: {
                phone: res.result,
                name:that.data.name,
                fenxiao: that.data.area,
                isagree: true,
                geneal: that.data.geneal,
            }, //接收参数
            success(res) {
                console.log(res)
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                }
                console.log(theJson)
            }
        })

        wx.request({
            url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
            method: 'POST',
            data: {
              activeId: 44,
              mobile: res.result,
              areaCode: that.data.area,
              agent: that.data.geneal,
              pageId: that.data.page
            },
            success: res => {
              console.log(res);
            }
          })
  
    }).catch(err => {
        console.error(err);
    });

  },

  tijiao: function (res) {
    var that = this;
    that.setData({
      theList:''
    })
    console.log(that.data)
    var name = that.data.name;
    var zkz = that.data.zkz;
    var leixing = that.data.leixing;
    var daima = that.data.daima;
    
    var e = /[^\u4E00-\u9FA5]/g;
    return "" == this.data.name ? (wx.showToast({
        title: "请输入姓名",
        icon: "none"
    }), !1) : e.test(this.data.name) ? (wx.showToast({
        title: "请输入正确的姓名",
        icon: "none"
    }), !1) : "" == this.data.zkz ? (wx.showToast({
        title: "请输入准考证号后三位",
        icon: "none"
    }), !1) :  

    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=47412&callback=?",
      data: {
        name: name,
        zkz: zkz,
        leixing: leixing,
        daima: daima,
        limits: '100'
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
        if (theJson.status == '2') {
          console.log('暂无数据！')
          that.setData({
            fixed: 1
          })
        } else {
          that.setData({
            theList: theJson.lists
          })
          wx.navigateTo({
            url: '../ms-result/ms-result',
          })
        }
        console.log(that.data.theList)
        wx.setStorageSync('result', that.data.theList)
      }
    })




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})